package panelSites;

import guiParts.EmailSendGui;
import info.clearthought.layout.TableLayout;

import java.awt.Color;
import java.awt.FlowLayout;
import java.awt.Insets;

import javax.swing.BorderFactory;
import javax.swing.JCheckBox;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.border.Border;
import javax.swing.border.CompoundBorder;
import javax.swing.border.EmptyBorder;

public class StatusPanel extends JPanel implements PanelSitesIface {

	/**
	 * this panel gives an overview. It is viewed with the button "status"
	 */
	private static final long serialVersionUID = 1L;

	// Betreff
	private JLabel betreffLabel = new JLabel("Betreff");
	private JTextArea betreffTextField = new JTextArea(1, 20);
	private JScrollPane betreffscrollpane = new JScrollPane(betreffTextField);

	// Inhalt
	private JLabel inhaltLabel = new JLabel("Nachrichtentext");
	private JTextArea inhaltTextArea = new JTextArea(10, 20);
	private JScrollPane inhaltscrollpane = new JScrollPane(inhaltTextArea);
	
	//Attachment
	private JLabel attLabel = new JLabel("Anhang");
	private JTextArea attPath = new JTextArea(1,20);
	private JScrollPane attScrollPane = new JScrollPane(attPath);
	
	//XLS
	private JLabel xlsLabel = new JLabel("XLS-Pfad");
	private JTextArea xlsPath = new JTextArea(1, 20);
	private JScrollPane xlsScrollPane = new JScrollPane(xlsPath);
	
	//Checkboxes
	private JLabel optionsLabel = new JLabel("Optionen");
	private JCheckBox html = new JCheckBox("HTML");
	private JCheckBox attachment = new JCheckBox("Anhang");
	private JPanel optionspanel = new JPanel(new FlowLayout(FlowLayout.LEFT, 0,0));
	Border border = BorderFactory.createLineBorder(Color.black);
	Border margin = new EmptyBorder(5, 10, 10, 10);
	
	
	
	
	
	
	
	private EmailSendGui view;

	public StatusPanel(EmailSendGui view) {
		this.view = view;

		//Subject
		betreffTextField.setText(view.getTmpBetreff());
		betreffTextField.setEditable(false);
		betreffTextField.setMargin(new Insets(5,5,5,5));
		
		betreffLabel.setBackground(Color.LIGHT_GRAY);
		betreffLabel.setOpaque(true);
		
		//Content
		inhaltTextArea.setText(view.getTmpContent());
		inhaltTextArea.setEditable(false);
		inhaltTextArea.setMargin(new Insets(5,5,5,5));
		
		inhaltLabel.setBackground(Color.LIGHT_GRAY);
		inhaltLabel.setOpaque(true);
		
		//Attachment
		attLabel.setBackground(Color.LIGHT_GRAY);
		attLabel.setOpaque(true);
		
		attPath.setText(view.getTmpAttachmentPath());
		attPath.setEditable(false);
		attPath.setWrapStyleWord(false);
		attPath.setMargin(new Insets(5,5,5,5));
		
		//XLS
		xlsLabel.setBackground(Color.LIGHT_GRAY);
		xlsLabel.setOpaque(true);
		
		xlsPath.setText(view.getTmpXlsPath());
		xlsPath.setEditable(false);
		xlsPath.setWrapStyleWord(false);
		xlsPath.setMargin(new Insets(5,5,5,5));
		
		//Options
		optionsLabel.setBackground(Color.LIGHT_GRAY);
		optionsLabel.setOpaque(true);
		html.setOpaque(false);
		attachment.setOpaque(false);
		
		//(de)activate boxes
		html.setSelected(view.getCheckBoxSet());
		attachment.setSelected(view.getCheckBoxSet());
		
		optionspanel.setBackground(Color.LIGHT_GRAY);
		optionspanel.setBorder(new CompoundBorder(border, margin));
		optionspanel.add(html);
		optionspanel.add(attachment);
		
		double size[][] = { { 150, TableLayout.FILL }, // Columns
				{ 10, 30, TableLayout.FILL,40 ,40,TableLayout.FILL } };// Rows

		TableLayout layout = new TableLayout(size);
		layout.setVGap(5);
		layout.setHGap(5);
		setLayout(layout);


		// Panel for the first line
		JPanel fillPanel = new JPanel();
		fillPanel.setBackground(Color.DARK_GRAY);
		add(fillPanel, "0,0, 1,0");
		
		//Second Line
		// Panel in the top-left corner
		JPanel containsPanel = new ContainsPanel(betreffLabel);
		add(containsPanel, "0,1");
		add(betreffscrollpane, "1,1");
		
		//Third
		containsPanel = new ContainsPanel(inhaltLabel);
		add(containsPanel, "0,2");
		add(inhaltscrollpane, "1,2");
		
		//Forth
		containsPanel = new ContainsPanel(attLabel);
		add(containsPanel, "0,3");
		add(attScrollPane, "1,3");
		
		//Fifth
		containsPanel = new ContainsPanel(xlsLabel);
		add(containsPanel, "0,4");
		add(xlsScrollPane, "1,4");
		
		//Sixth - Options
		containsPanel = new ContainsPanel(optionsLabel);
		add(containsPanel, "0,5");
		add(optionspanel, "1,5");
		
		// Panel for the rest
		fillPanel = new JPanel();
		fillPanel.setBackground(Color.DARK_GRAY);
		add(fillPanel, "0,6 , 1,6");

	}

	public String getText() {
		return "status text - no need for";
	}

	public void setText(String text) {
		betreffTextField.setText(view.getTmpBetreff());
		inhaltTextArea.setText(view.getTmpContent());
		attPath.setText(view.getTmpAttachmentPath());
		xlsPath.setText(view.getTmpXlsPath());
	}

	public boolean getHtmlCheckBox() {
		return html.isSelected();		
	}
	
	public boolean getAttachmentCheckBox() {
		return attachment.isSelected();		
	}
}
